package world.criver.mm_vworld_server.service;

import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.node.ObjectNode;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import world.criver.mm_vworld_server.config.conConfig;
import world.criver.mm_vworld_server.data.daSave;
import world.criver.mm_vworld_server.enums.enumKey;
import world.criver.mm_vworld_server.function.funAdminMessage;
import world.criver.mm_vworld_server.function.funAdminVerifyCode;

@Service
public class serAdminSave {
    @Autowired
    private conConfig conConfig;
    @Autowired
    private funAdminMessage funAdminMessage;
    @Autowired
    private funAdminVerifyCode funAdminVerifyCode;

    private ObjectMapper om=new ObjectMapper();

    public ObjectNode properties(JsonNode info){
        if(!info.has(enumKey.verifyCode.name()))return funAdminMessage.error("缺少VerifyCode");
        String code=info.get(enumKey.verifyCode.name()).asText();
        if(!conConfig.isTest())if(!funAdminVerifyCode.test(code))return funAdminMessage.error("已在其他地方登陆");
        ObjectNode on=om.createObjectNode();
        on.put(enumKey.properties.name(), om.valueToTree(daSave.properties));
        on.put(enumKey.status.name(), true);
        return on;
    }
}
